class Solution
{
public:
    int maximumRows(vector<vector<int>> &matrix, int numSelect)
    {
        int m = matrix.size();
        int n = matrix[0].size();
        vector<int> rowMasks(m, 0);
        for (int i = 0; i < m; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                rowMasks[i] |= matrix[i][j] << j;
            }
        }

        int maxCover = 0;
        int maxSelection = (1 << n) - 1;
        for (int selection = 0; selection <= maxSelection; ++selection)
        {
            if (__builtin_popcount(selection) != numSelect)
            {
                continue;
            }
            int cover = 0;
            for (auto rowMask : rowMasks)
            {
                if ((rowMask | selection) == selection)
                {
                    ++cover;
                }
            }
            maxCover = max(maxCover, cover);
        }
        return maxCover;
    }
};